<link href="/admins/css/adminshare.css" rel="stylesheet" type="text/css" />
<link href="/admins/css/yundan.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/boxy/js/jquery.boxy.js"></script>
<link href="/js/boxy/css/boxy.css" media="screen" rel="stylesheet" type="text/css" >  
<script type="text/javascript">
    $(function(){
        window.alert = Boxy.alert;
        window.confirm = Boxy.confirm;
    });
</script>
<style>
    .qudao dl{clear: both}
    .yundantopleft .yundancz .nui-toolbar-item{margin: 10px 20px 0 0;}
</style>
<div class="jobdetail" <?php echo $this->actype?"style='display:none;'":"";?>>
    <div class="admin_nrtop">
        <div class="yundantopleft">
            <div class="yundancz">
                <div class="nui-toolbar-item">
                    <div class="nui-btn ">
                        <a href="/admini/autotask/index" class="nui-btn-text"><span>&lt;&lt;</span>返回</a>
                    </div>
                </div>                    
                <div class="nui-toolbar-item">
                    <div class="nui-btn ">
                        <a href="javascript:void(0);" class="nui-btn-text executeJob" name="<?php echo $this->jobItem->Id;?>">执行</a>
                    </div>
                    <div class="nui-btn ">
                        <a href="javascript:void(0);" class="nui-btn-text editJob">修改信息</a>
                    </div>
                </div>     
            </div>
        </div>
    </div>    
    <div class="buzhou" style="clear:both;height:1px;"></div>
    <div class="yundan_top">
        <table class="yunxinxi">
            <tr>
                    <td class="ydleft">
                    <div class="zhuangtai">
                        <i></i><h1><?php echo $this->jobItem->name;?></h1>
                    </div>
                </td>
                <td class="ydtopline">
                    <div class="zhtailan">
                        <label>状态栏：</label>
                    </div>
                </td>
            </tr>
            <tr>
                    <td class="ydleft">
                        <table>
                            <tr>
                            <td class="xleft">创建时间：</td>
                            <td class="xlright"><?php echo $this->jobItem->DateCreated;?></td>
                            <td class="xleft">任务类型：</td>
                            <td class="xlright"><?php echo $this->jobItem->TypeName;?></td>
                        </tr>
                        <tr>
                            <td class="xleft">任务名称：</td>
                            <td class="xlright" colspan="3"><?php echo $this->jobItem->name;?></td>
                        </tr>
                        <tr>
                            <td class="xleft">任务描述：</td>
                            <td class="xlright" colspan="3"><?php echo $this->jobItem->Description;?></td>
                        </tr>
                         <tr>
                            <td class="xleft">是否启用：</td>
                            <td class="xlright"><?php echo $this->jobItem->DisableName;?></td>
                            <td class="xleft">执行类型：</td>
                            <td class="xlright"><?php echo $this->jobItem->ExecuteName;?></td> 
                        </tr>
                        <tr>
                            <td class="xleft">执行时间：</td>
                            <td class="xlright"><?php echo $this->jobItem->ExecuteTime;?></td>      
                        </tr>
                    </table>
                </td>
                <td class="ydtopline sdq">
                    <table class="yddizhi">
                        <tr>
                            <td class="dzl" style="width: 90px;">执行类型：</td>
                            <td><?php echo $this->jobItem->ExecuteName;?></td>
                        </tr>
                            <tr>
                            <td class="dzl">执行次数：</td>
                            <td><?php echo $this->jobItem->count;?></td>
                        </tr>
                            <tr>
                            <td class="dzl">最后执行状态：</td>
                            <td><?php echo $this->jobItem->LastStatusName;?></td>
                        </tr>
                        <tr>
                            <td class="dzl">最后执行时间：</td>
                            <td><?php echo $this->jobItem->dateLast?$this->jobItem->dateLast:"暂无";?></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="ydleft" colspan="2">
                    <table>
                        <tr>
                            <td class="xleft">执行内容：</td>
                            <td><?php echo $this->jobItem->content;?></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div class="ydbottom">
        <div class="chuku">
            <div class="lanmu">
                <h2>运行日志</h2>
            </div>
            <div class="wupintable" style="width: 1650px;margin: 5px 25px;">
                <div class="biaotbody">
                    <table>
                        <tr>
                            <th class="li20"><div class="lijz">开始时间</div></th>
                            <th class="li20"><div class="lijz">结束时间</div></th>
                            <th class="li20"><div class="lijz">序号</div></th>
                            <th class="li20"><div class="lijz">状态</div></th>
                            <th class="li20"><div class="lijz">类型</div></th>
                        </tr>
                    </table>
                </div>
                <div class="table" style="height: 280px;overflow: auto;">
                    <table>
                        <?php if($this->jobLogItem){ ?>
                            <?php foreach ($this->jobLogItem as $jobLogVal) { ?>
                            <tr>
                                <td class="li20"><div class="lijz"><?php echo $jobLogVal->StartTime;?></div></td>
                                <td class="li20"><div class="lijz"><?php echo $jobLogVal->StopTime;?></div></td>
                                <td class="li20"><div class="lijz"><?php echo $jobLogVal->CountTime;?></div></td>
                                <td class="li20"><div class="lijz"><?php echo $jobLogVal->StatusName;?></div></td>
                                <td class="li20"><div class="lijz"><?php echo $jobLogVal->Content;?></div></td>
                            </tr>
                            <?php } ?>
                        <?php } ?>
                    </table>
                </div>    
            </div>
        </div>
    </div>
</div>
<style>
    .editdetail table{border: #fff solid 1px;width: 99%;font-size: 16px;}
    .editdetail table td{height: 30px;border-bottom: #fff solid 1px;border-right: #fff solid 1px;padding-top: 5px;vertical-align: top;}
    .editdetail table textarea{width: 540px;height: 120px;margin:5px 0px 5px 10px;border: 1px solid #3197B5;font-size: 16px;padding: 5px;}
    .editdetail table .lefttd{text-align: right;padding-right: 10px;width: 100px;padding-top: 10px;}
    .editdetail table .righttd{width: 320px;}
    .editdetail table td *{font-size: 16px;margin-left: 10px;border: 1px solid #3197B5;padding: 5px;}
    #jobTimeMonth {border:none;width:90%;float: left;margin-left: 0px;padding: 0px;margin-top: 10px;}
    #jobTimeMonth .monthNo{border:none;padding-left: 1px;float:left;width: 70px;}
    #jobTimeMonth .monthCkNo{border: 1px solid #3197B5;width: 68px;padding-left: 1px;float:left;}
</style>
<div class="editdetail" <?php echo $this->actype?"style='display:block;'":"style='display:none;'";?>>
    <div class="ydbottom">
        <div class="chuku">
            <div class="lanmu">
                <h2>修改信息</h2>
            </div>
            <div>
                <form action="" method="post" id="editJobDetail">
                <table>
                    <tr>
                        <td class="lefttd">任务名称：<input type="hidden" id="jobId" name="jobId" value="<?php echo $this->jobItem->Id;?>" /></td>
                        <td colspan="3" class="righttd"><input type="text" id="jobName" name="jobName" value="<?php echo $this->jobItem->Name;?>" style="width:540px;"/></td>
                    </tr>
                    <tr>
                        <td class="lefttd">任务描述：</td>
                        <td colspan="3" class="righttd"><textarea id="jobDescription" name="jobDescription" ><?php echo $this->jobItem->Description;?></textarea></td>
                    </tr>
                    <tr>
                        <td class="lefttd">是否启用：</td>
                        <td class="righttd"><select id="jobDisable" name="jobDisable">
                            <?php foreach ($this->jobDisableAll as $disableKey => $disableVal) { ?>
                                <option value="<?php echo $disableKey;?>" <?php echo $this->jobItem->isDisable == $disableKey?"selected":"";?> ><?php echo $disableVal;?></option>
                            <?php } ?>
                            </select></td>
                        <td class="lefttd">任务类型：</td>
                        <td><select id="jobType" name="jobType">
                            <?php foreach ($this->jobTypeAll as $typeKey => $typeVal) { ?>
                                <option value="<?php echo $typeKey;?>" <?php echo $this->jobItem->type == $typeKey?"selected":"";?> ><?php echo $typeVal;?></option>
                            <?php } ?>
                            </select></td>
                    </tr>
                    <tr>
                        <td class="lefttd">执行内容：</td>
                        <td colspan="3" class="righttd"><textarea id="jobContent" name="jobContent" ><?php echo $this->jobItem->Content;?></textarea></td>
                    </tr>
                    <tr>
                        <td class="lefttd">执行类型：</td>
                        <td colspan="3" class="righttd">
                            <?php foreach ($this->jobExecuteAll as $executeKey => $executeVal) { ?>
                            <div style="margin-left: 0px;width: 100px;float: left;border: none;">
                                <input type="radio" id="jobExecute<?php echo $executeKey;?>" name="jobExecute" value="<?php echo $executeKey;?>" <?php echo $this->jobItem->dateType == $executeKey?"checked":"";?> style="border: 1px solid #3197B5;margin-right: 5px;"/><?php echo $executeVal;?>
                            </div>
                            <?php } ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="lefttd">执行时间：</td>
                        <td colspan="3" class="righttd">
                            <div id="jobtime" style="border:none;margin-left: -5px;width: 80px;float: left;">
                                <select id="jobTime" name="jobTime">
                                    <option value="-1" <?php echo $this->jobItem->time == Application_Model_Job::Execute_ForTime?"selected":"";?>>循环</option>
                                    <?php 
                                        $arrRunDate = explode(",", $this->jobItem->dateValue);
                                        for($i=0;$i<24;$i++){
                                            $html = "<option ";
                                            $html .= $this->jobItem->time==$i?"selected":"";
                                            $html .= " value='".$i."'>".($i<10?"0$i":$i).":00</option>";
                                            echo $html;
                                        }
                                    ?>
                                </select>
                            </div>
                            <div id="jobfortime"  style="border:none;width: 500px;float: left;height: 40px;">
                                请输入任务循环执行间隔时间：<input type="text" id="fortime" name="fortime" value="<?php echo $this->jobItem->timeLog;?>" onkeyup="value=value.replace(/[^\d]/g,'')"/></div>
                            <div id="jobTimeWeek" style="border:none;width:90%;float: left;margin-left: 0px;padding: 0px;<?php echo $this->jobItem->dateType == Application_Model_Job::Execute_Week?"":"display:none;";?>">
                                <label style="border:none;margin-left: 0px;padding: 0px;">
                                    <input id="dateValue1" name="dateValueW[]" type="checkbox" value="1" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(1, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周一</label> 
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue2" name="dateValueW[]" type="checkbox" value="2" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(2, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周二</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue3" name="dateValueW[]" type="checkbox" value="3" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(3, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周三</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue4" name="dateValueW[]" type="checkbox" value="4" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(4, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周四</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue5" name="dateValueW[]" type="checkbox" value="5" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(5, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周五</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue6" name="dateValueW[]" type="checkbox" value="6" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(6, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周六</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue0" name="dateValueW[]" type="checkbox" value="0" <?php echo ($this->jobItem->dateType == Application_Model_Job::Execute_Week && in_array(0, $arrRunDate))?"checked":"";?>/>&nbsp;&nbsp;周日</label>
                            </div>
                            <div id="jobTimeMonth" style="<?php echo $this->jobItem->dateType == Application_Model_Job::Execute_Month?"":"display:none;";?>">
                                <?php 
                                    for($j=1;$j<32;$j++){
                                        $html = '<div class="monthNo"><input id="dateValue'.$j.'" name="dateValueM[]" type="checkbox" value="'.$j.'" ';
                                        $html .= ($this->jobItem->dateType == Application_Model_Job::Execute_Month && in_array($j, $arrRunDate))?"checked":"";
                                        $html .= " />&nbsp;&nbsp;".($j<10?"0$j":$j)."号</div>";
                                        $html .= $j==16?"<div style='border:none;width:99%;float:left;height: 1px;'></div>":"";
                                        
                                        echo $html;
                                    }
                                ?>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="lefttd"></td>
                        <td colspan="3" class="righttd">
                            <a class="anvbotton5 subEdit" href="javascript:void(0)" style="font-size: 16px;margin-left: 0px;border: none;padding: 0px;"><span style="margin-left: 0px;border: none;padding: 0 25px;">确认</span></a>
                            <a class="anvbotton4 reEdit" href="javascript:void(0)" style="font-size: 16px;border: none;padding: 0px;"><span style="margin-left: 0px;border: none;padding: 0 25px;">取消</span></a>
                        </td>
                    </tr>
                </table>
            </form>
            </div> 
        </div>
    </div>
</div>
<script>
$(function(){
    $("input[type='checkbox']").each(function(index,item){
        if($(item).attr("checked")){
            $(item).parent("div").addClass("monthCkNo");
            $(item).parent("div").removeClass("monthNo");
        }
        $(item).click(function(){
            if($(this).attr("checked")){
                $(this).parent("div").addClass("monthCkNo");
                $(this).parent("div").removeClass("monthNo");
            } else {
                $(this).parent("div").removeClass("monthCkNo");
                $(this).parent("div").addClass("monthNo");
            }
        });
    });
    $("input[type='radio'][name='jobExecute']").click(function(){
        var jobExecute = $(this).val();
        if(jobExecute == <?php echo Application_Model_Job::Execute_Week;?>){
            $("#jobTimeWeek").show();
            $("#jobTimeMonth").hide();
            return ;
        }
        if(jobExecute == <?php echo Application_Model_Job::Execute_Month;?>){
            $("#jobTimeWeek").hide();
            $("#jobTimeMonth").show();
            return ;
        }
        $("#jobTimeWeek").hide();
        $("#jobTimeMonth").hide();
        return ;
    });
});
$(function(){
    $(".executeJob").click(function(){
        var id = $(this).attr("name");
        $(this).text("执行中");
        confirm("您确认该任务现需要手工执行下？",function(){
            $.post("/admini/job/indexone",{"id":id},function(data){
               if(data == 1){
                   alert("执行成功！");
                   location.reload();
               } else {
                   alert("出现未知错误！");
               }
            });
        });
    });
    $(".editJob").click(function(){
        $(".jobdetail").hide();
        $(".editdetail").show();
    });
    $(".reEdit").click(function(){
        $(".jobdetail").show();
        $(".editdetail").hide();
    });
    $(".subEdit").click(function(){
        var jobName = $("#jobName").val();
        var jobDescription = $("#jobDescription").val();
        var jobContent = $("#jobContent").val();
        var jobTime = $("#jobTime").val();
        var fortime = $("#fortime").val();
        var jobExecute = $("input[type='radio'][name='jobExecute']:checked").val();
        var dateValueW = $("input[type='checkbox'][name='dateValueW[]']:checked").length;
        var dateValueM = $("input[type='checkbox'][name='dateValueM[]']:checked").length;
        if(jobName == ""){
            alert("任务名称不能为空");
            return ;
        }
        if(jobDescription == ""){
            alert("任务描述不能为空");
            return ;
        }
        if(jobContent == ""){
            alert("执行内容不能为空");
            return ;
        }
        if(jobTime == <?php echo Application_Model_Job::Execute_ForTime;?> && fortime == ""){
            alert("循环时间不能为空");
            return ;
        }
        if(jobExecute == <?php echo Application_Model_Job::Execute_Week;?> && dateValueW == 0){
            alert("每周运行的日期不能为空");
            return ;
        }
        if(jobExecute == <?php echo Application_Model_Job::Execute_Month;?> && dateValueM == 0){
            alert("每月运行的日期不能为空");
            return ;
        }
        $("#editJobDetail").submit();
    });
});
</script>
